<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <style>
        * {
            list-style: none;
            margin: 0;
            padding: 0;
        }

        #shop-car li {
            border: 1px dotted red;
            margin: 20px 0;
            padding: 20px;
        }

        .container {
            width: 400px;
            padding: 20px;
        }
    </style>

    <div class="container">



        <ul id="shop-car">
            <li>
                <input type="checkbox" />
                <div class="shop">商品名称:</div>
                <img src="" alt="">
                <div class="price">商品价格:</div>
                <div class="num">购买数量:</div>
                <div class="color">商品规格:</div>
                <div class="xuan"></div>
            </li>
            <li>
                <input type="checkbox" />
                <div class="shop">商品名称:</div>
                <img src="" alt="">
                <div class="price">商品价格:</div>
                <div class="num">购买数量:</div>
                <div class="color">商品规格:</div>
                <div class="xuan"></div>
            </li>
        </ul>
        <p id="totalnum"></p>

    </div>
    <script>
        let products = [
            {
                goods_name: '小米10-1',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '500',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 10,
                goods_is_checked: true
            },
            {
                goods_name: '小米10-2',
                goods_img: 'https://img12.360buyimg.com/n0/s80x80_jfs/t1/118064/27/12885/59959/5f17b7efE453f688d/5b33ac76b2aaea9b.jpg',
                goods_price: '510',
                goods_attr: '砂石黑4GB+64GB',
                goods_num: 50,
                goods_is_checked: false
            }
        ]
        let Ul = document.querySelector('ul')
        let li = document.querySelectorAll('li')
        let inp = document.querySelectorAll('li input')
        let tot = document.querySelector('#totalnum')
        // console.log(inp)
        for (let i = 0; i < products.length; i++) {
            li[i].innerHTML = ` <input type="checkbox" />
                <div class="shop">商品名称:${products[i].goods_name}</div>
                <img src="${products[i].goods_img}" alt="">
                <div class="price">商品价格:${products[i].goods_price}</div>
                <div class="num">购买数量:${products[i].goods_num}</div>
                <div class="color">商品规格:${products[i].goods_attr}</div>`
            if (products[i].goods_is_checked == true) {
                li[i].innerHTML += `<div class="xuan">选中</div>`
                tot.innerHTML = `总数量：${products[i].goods_num}`
            } else {
                li[i].innerHTML += `<div class="xuan">不选中</div>`
            }

        }
    </script>
</body>

</html>